var util = require("../../../utils/util.js");
var api = require('../../../config/api.js');
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    appointList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.loadAppointInfo();
  },
  loadAppointInfo: function () {
    var that = this;
    var userid = wx.getStorageSync("userid");
    if(userid == ''){
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
      return;
    }
    util.request(api.CoachAppointList, {uid:userid,key:api.key}).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          appointList: res.data
        });
      }else if(res.errno === 402){
        wx.showModal({
          title: '错误',
          content:'不被允许的请求',
          showCancel: false
        })
    }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  bindSignIn: function (e) {
    var hasLogin = wx.getStorageSync("app.globalData.hasLogin");
    if (!hasLogin) {
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
    }

    var that=this;
    var id = e.currentTarget.dataset.id;
    var userid = wx.getStorageSync("userid");
    if(userid == ''){
      wx.navigateTo({
        url: "/pages/auth/login/login"
      });
      return;
    }
    util.request(api.CoachAppointSignIn, {
      id: id,uid:userid,
      key:api.key
    }).then(function (res) {
      if (res.errno === 0) {
        wx.showToast({
          title: '签到成功！'
        })
      }else if(res.errno === 402){
        wx.showModal({
          title: '错误',
          content:'不被允许的请求',
          showCancel: false
        })
    }
      that.loadAppointInfo();
    });

  }
})